ESP3D Lib  1.0
3D Printer WiFi Library
wificonfig.h
Go to the documentation of this file.
1 /*
2  wificonfig.h - wifi functions class
3 
4  Copyright (c) 2014 Luc Lebosse. All rights reserved.
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 //Services that need to be used
22 #include "esplibconfig.h"
23 
24 #define ENABLE_MDNS
25 #define ENABLE_OTA
26 #define ENABLE_HTTP
27 #define ENABLE_SSDP
28 #define ENABLE_CAPTIVE_PORTAL
29 //Authentication flag is now in Configuration_adv.h
30 //#define ENABLE_AUTHENTICATION
31 #define ENABLE_SERIAL2SOCKET_OUT
32 
33 #define ENABLE_SERIAL2SOCKET_IN
34 
35 //Preferences entries
36 #define NAMESPACE "MARLIN"
37 #define HOSTNAME_ENTRY "ESP_HOSTNAME"
38 #define STA_SSID_ENTRY "STA_SSID"
39 #define STA_PWD_ENTRY "STA_PWD"
40 #define STA_IP_ENTRY "STA_IP"
41 #define STA_GW_ENTRY "STA_GW"
42 #define STA_MK_ENTRY "STA_MK"
43 #define ESP_WIFI_MODE "WIFI_MODE"
44 #define AP_SSID_ENTRY "AP_SSID"
45 #define AP_PWD_ENTRY "AP_PWD"
46 #define AP_IP_ENTRY "AP_IP"
47 #define AP_CHANNEL_ENTRY "AP_CHANNEL"
48 #define HTTP_ENABLE_ENTRY "HTTP_ON"
49 #define HTTP_PORT_ENTRY "HTTP_PORT"
50 #define TELNET_ENABLE_ENTRY "TELNET_ON"
51 #define TELNET_PORT_ENTRY "TELNET_PORT"
52 #define STA_IP_MODE_ENTRY "STA_IP_MODE"
53 
54 //Wifi Mode
55 #define ESP_WIFI_OFF 0
56 #define ESP_WIFI_STA 1
57 #define ESP_WIFI_AP 2
58 
59 #define DHCP_MODE 0
60 #define STATIC_MODE 0
61 
62 //Switch
63 #define ESP_SAVE_ONLY 0
64 #define ESP_APPLY_NOW 1
65 
66 //defaults values
67 #define DEFAULT_HOSTNAME "marlinesp"
68 #define DEFAULT_STA_SSID "MARLIN_ESP"
69 #define DEFAULT_STA_PWD "12345678"
70 #define DEFAULT_STA_IP "0.0.0.0"
71 #define DEFAULT_STA_GW "0.0.0.0"
72 #define DEFAULT_STA_MK "0.0.0.0"
73 #define DEFAULT_WIFI_MODE ESP_WIFI_AP
74 #define DEFAULT_AP_SSID "MARLIN_ESP"
75 #define DEFAULT_AP_PWD "12345678"
76 #define DEFAULT_AP_IP "192.168.0.1"
77 #define DEFAULT_AP_MK "255.255.255.0"
78 #define DEFAULT_AP_CHANNEL 1
79 #define DEFAULT_WEBSERVER_PORT 80
80 #define DEFAULT_HTTP_STATE 1
81 #define HIDDEN_PASSWORD "********"
82 
83 //boundaries
84 #define MAX_SSID_LENGTH 32
85 #define MIN_SSID_LENGTH 1
86 #define MAX_PASSWORD_LENGTH 64
87 //min size of password is 0 or upper than 8 char
88 //so let set min is 8
89 #define MIN_PASSWORD_LENGTH 8
90 #define MAX_HOSTNAME_LENGTH 32
91 #define MIN_HOSTNAME_LENGTH 1
92 #define MAX_HTTP_PORT 65001
93 #define MIN_HTTP_PORT 1
94 #define MAX_TELNET_PORT 65001
95 #define MIN_TELNET_PORT 1
96 #define MIN_CHANNEL 1
97 #define MAX_CHANNEL 14
98 
99 
100 #ifndef _WIFI_CONFIG_H
101 #define _WIFI_CONFIG_H
102 
103 #include <WiFi.h>
104 
105 class WiFiConfig {
106 public:
107  WiFiConfig();
108  ~WiFiConfig();
109  static void wait(uint32_t milliseconds);
110  static bool isValidIP(const char * string);
111  static bool isPasswordValid (const char * password);
112  static bool isSSIDValid (const char * ssid);
113  static bool isHostnameValid (const char * hostname);
114  static uint32_t IP_int_from_string(String & s);
115  static String IP_string_from_int(uint32_t ip_int);
116 
117  static bool StartAP();
118  static bool StartSTA();
119  static void StopWiFi();
120  static int32_t getSignal (int32_t RSSI);
121  static void begin();
122  static void end();
123  static void handle();
124  static void restart_ESP();
125 
126  private :
127  static bool ConnectSTA2AP();
128  static void WiFiEvent(WiFiEvent_t event);
129  static bool restart_ESP_module;
130 };
131 
132 extern WiFiConfig wifi_config;
133 
134 #endif
wifi_config
WiFiConfig wifi_config
WiFiConfig::begin
static void begin()
WiFiConfig::StopWiFi
static void StopWiFi()
WiFiConfig
Definition: wificonfig.h:105
WiFiConfig::isPasswordValid
static bool isPasswordValid(const char *password)
WiFiConfig::end
static void end()
WiFiConfig::StartAP
static bool StartAP()
WiFiConfig::isHostnameValid
static bool isHostnameValid(const char *hostname)
WiFiConfig::handle
static void handle()
WiFiConfig::getSignal
static int32_t getSignal(int32_t RSSI)
WiFiConfig::isValidIP
static bool isValidIP(const char *string)
esplibconfig.h
WiFiConfig::~WiFiConfig
~WiFiConfig()
WiFiConfig::WiFiConfig
WiFiConfig()
WiFiConfig::StartSTA
static bool StartSTA()
WiFiConfig::IP_string_from_int
static String IP_string_from_int(uint32_t ip_int)
WiFiConfig::isSSIDValid
static bool isSSIDValid(const char *ssid)
WiFiConfig::restart_ESP
static void restart_ESP()
WiFiConfig::wait
static void wait(uint32_t milliseconds)
WiFiConfig::IP_int_from_string
static uint32_t IP_int_from_string(String &s)